/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mydatastore.mysql.client;

import com.mydatastore.StatementUnit;
import com.mydatastore.entity.Client;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author DTIT
 */
public class AddClient extends StatementUnit{
 
  private Client client;

  public AddClient(Client client) {
    this.client = client;
  }
  
  @Override
  public void composeSql() {
    append("INSERT INTO client (client_fn, client_mn, client_ln, client_age, client_sex)");
    append("VALUES (?, ?, ?, ?, ?)");
  }

  @Override
  public PreparedStatement getPreparedStatement(Connection connection) throws SQLException {
    PreparedStatement st = connection.prepareStatement(getSql(), Statement.RETURN_GENERATED_KEYS);
    st.setString(1, client.getFirstName());
    st.setString(2, client.getMiddleName());
    st.setString(3, client.getLastName());
    st.setInt(4, client.getAge());
    st.setString(5, client.getSex().name());
    return st;
  }
}
